package com.qtjf.qtmoneyservice.utils;

import android.util.Log;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.qtjf.qtmoneyservice.MyApplication;
import com.qtjf.qtmoneyservice.constantSet.Constant;

import java.util.HashMap;
import java.util.Map;

import impl.IHttpListener;

/**
 * Created by Administrator on 2017/8/24 0024.
 */

public class RequestNetApi {

    IHttpListener iHttpListener;
    public void attach(IHttpListener iHttpListener)
    {
        this.iHttpListener=iHttpListener;
    }

    public void postHttp(String url,final HashMap<String,String> map)
    {
            final StringRequest stringRequest = new StringRequest(Request.Method.POST, Constant.HOMEADDRESS+url,  new Response.Listener<String>() {

                @Override
                public void onResponse(String response) {
                    // TODO Auto-generated method stub
                    iHttpListener.success(response);
            }
        }, new Response.ErrorListener(){

        @Override
        public void onErrorResponse(VolleyError error) {
            // TODO Auto-generated method stub
            iHttpListener.fail();
           // Log.d("999",error.getMessage());
        }

    }){
        // 需要重写获取参数的函数,可以向服务器提交参数
        protected Map<String,String> getParams() throws AuthFailureError {
            return map;
        }
    };
    MyApplication.getQueue().add(stringRequest);
    }
}
